﻿
using GameFramework.events;
using GameFramework.UI;
using UnityEngine.UI;
using UnityEngine.UIElements;

namespace Game.ui
{
    [View(SceneViewManagerName = SceneViewManagerNames.Home)]
    [Presenter(type = typeof(SetNamingPresenter))]
    public class SetNamingView:BaseView
    {   
        [UIBind(ClassName = "inputArea")]
        public TextField nameInput;
        [UIBind(ClassName = "submitBtn")]
        public Label submitLabel;

        public override void init()
        {
            base.init();
            elementRegisterCallBack<ClickEvent>(submitLabel,e=>setName());
        }

        protected override void modelPrepared(object data)
        {
            var baseInfoData = data as BaseInfoData;
            if (baseInfoData.Name != null && baseInfoData.Name.Length > 0)
            {
                
                nameInput.value = baseInfoData.name;
            }
        }

        private void setName()
        {
            string name = nameInput.text;
            MVPEventManager.Instance.SetNamingView_V2P_SetName?.Invoke(name);
        }
        
    }
}
